﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KopainConcept.Exception
{

    /// <summary>This is the base class for all exceptions thown in this DLL.
    /// </summary>
    public abstract class Kopain2Exception : System.Exception
    {
        protected Kopain2Exception ( string message, System.IO.FileNotFoundException innerException )
            :base( message, innerException )
	    {

	    }
    }

    /// <summary>This exception is for handling when a file was not found.
    /// </summary>
    public class FileWasNotFoundException : Kopain2Exception
    {

        /// <summary>This is as getter for the PathFilenameSuffix stored in the original exception (inner exception).
        /// </summary>
        public LIUS.Beta.FileSystem.PathFileSuffix.PathFilenameSuffix PathFilenameSuffix
        {
            get
            {
                return CreatePathFilenameSuffix( ((System.IO.FileNotFoundException)InnerException).FileName);
            }
        }

        /// <summary>This constructor takes all necessary data.
        /// </summary>
        /// <param name="innerException"></param>
        public FileWasNotFoundException( System.IO.FileNotFoundException innerException )
            :base( string.Format( "File [{0}] was not found exception.", CreatePathFilenameSuffix(innerException.FileName)), innerException )
        {
        }

        /// <summary>This helper method just creates a PathFilenameSuffix out of the string.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private static LIUS.Beta.FileSystem.PathFileSuffix.PathFilenameSuffix CreatePathFilenameSuffix( string fileName )
        {
            return new LIUS.Beta.FileSystem.PathFileSuffix.PathFilenameSuffix( fileName, LIUS.Beta.FileSystem.PathFileSuffix.HandleValue.RequireExact );
        }

    }

}
